package com.uxwine.cmm.os;

import android.content.Context;
import android.os.PowerManager;

public class CPUWakeLock {
	
	private PowerManager.WakeLock mCpuWakeLock;

    public void acquire(Context context, String name) {
        if (mCpuWakeLock != null) {
            return;
        }

        PowerManager pm =
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);

        mCpuWakeLock = pm.newWakeLock(
                PowerManager.PARTIAL_WAKE_LOCK |
                PowerManager.ACQUIRE_CAUSES_WAKEUP |
                PowerManager.ON_AFTER_RELEASE, name);
        mCpuWakeLock.acquire();
    }

    public void release() {
        if (mCpuWakeLock != null) {
        	mCpuWakeLock.release();
        	mCpuWakeLock = null;
        }
    }
}
